mini core

The Core Language

Euphoria uses simple English like syntax. Euphoria is very predictable; once you learn a concept you can apply it to all forms of data.

Objects:

All data objects in Euphoria are either atoms or sequences. An atom is a single numeric value. A sequence is an ordered list of data objects. The objects in a sequence can be an arbitrary mix of atoms or sequences.

Here are some Euphoria objects:

0 
1_000							 
-1e6								-- length 1, one item 
{2, 3, 5, 7, 11, 13, 17, 19} 
{1, 2, {3, 3, 3}, 4, {5, {6}}} 
{{"john", "smith"}, 5552389, 97.25} -- length 3, three items 
{}   								-- length 0, zero sequence 

A string such as "ABCD" is just another way of writing {65, 66, 67, 68}, that is the sequence of Unicode values equal to ASCII codes.

Expressions:

The following operators can be used in building expressions. Each expression results in a Euphoria object as a result:

        --highest precedence:   
function/type calls 
unary- not 
* / 
+ - 
& 
< > <= >= = != 
and or 
        --lowest precedence:    
 
example: {1, 2, 3} + 5 results in {6, 7, 8} 

Subscripting of Sequences:

A single item of a sequence can be selected by giving the item number in brackets. Item numbers start at one. For example, if variable x contains the value {5, 7, 9, 11, 13} then x[2] is 7. If we reassign x[2] = {11, 22, 33} then x becomes: {5, {11, 22, 33}, 9, 11, 13}

Multiple subscripts can appear on the left or right of the assignment. If x is { {1,2,3}, {5, 7, 9} } then x[2][3] is 9.

Slicing of Sequences:

Euphoria lets you select a slice from a sequence. A slice is a sequence of consecutive elements. For example if x is {1, 1, 2, 2, 2, 1, 1} then x[3..5] is {2, 2, 2}. x[3..3] is {2} and x[3..2] is {}.

Concatenation of Objects:

The & operator will concatenate two objects into a longer sequence. For example {1, 2, 3} & {4, 5, 6} is {1, 2, 3, 4, 5, 6}. Atoms can also be concatenated: 6.5 & 9 is {6.5, 9}. {1, 2, 3} & 4 is {1, 2, 3, 4}.

Arithmetic Operations on Objects:

Any binary or unary arithmetic operation, including any of the built-in math routines, can be applied to entire sequences as well as to atomic numbers. For example,

{1, 2, 3} + {4, 5, 6} is {5, 7, 9} 
{{1, 2}, {3, 4}, {5}} * {4, 5, 6} is {{4, 8}, {15, 20}, {30}} 

Declarations:

Variables are declared by listing a type-name followed by a list of variables names. For example,

integer x, y, z 
integer x=1, y=4.5, z=1_000 
atom a 
sequence s1, s2="Hello Euphoria!" 
object fred, george={{4, 8}, {15, 20}, {30}} 

The types: integer, atom, sequence and object are predefined. Other types can be created as user defined types (UDT), a one-parameter type function that returns true (!0) when a value belongs to the type and false (0) when it does not. Variables declared as object can take on any value, (atom or sequence). Those declared as atom must be atoms. Those declared as sequence must be assigned sequences. Those declared as integer must be assigned atoms that are integer values in the range of roughly ± one billion.

Subroutines come in three flavors: procedures, functions and types. Procedures do not return a value. Functions and types do. Types are just one-parameter functions, used in defining new user-defined types for declaring variables.

Not Categorized, Please Help

Search



Quick Links

User menu

Not signed in.

Misc Menu